package com.xyzwps.server.paimon.app.filter

import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint
import org.springframework.stereotype.Component

@Aspect
@Component
class AppFilterAspect {

    @Around("@annotation(appFilter)")
    fun logAction(joinPoint: ProceedingJoinPoint, appFilter: AppFilter): Any? {
        if (appFilter.value.isEmpty()) {
            return joinPoint.proceed()
        }

        if (joinPoint is MethodInvocationProceedingJoinPoint) {
            for (appFilterToken in appFilter.value) {
                when (appFilterToken) {
                    AppFilterToken.AUTH -> TokenAuth.check(joinPoint)
                }
            }
        }
        return joinPoint.proceed()
    }
}
